import 'package:flutter/material.dart';
import 'package:gold/http/api_login.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';
import 'package:gold/base/provider_scaffold.dart';
import 'package:gold/ui/my/withdrawal/withdrawal_details_viewmodel.dart';
import 'package:gold/utils/xfg_color.dart';
import 'package:gold/utils/xfg_size.dart';
import 'package:gold/widgets/common_widgets.dart';
import 'package:gold/widgets/xfg_text.dart';

/// @description: 提现成功
/// @author tangzhentao
/// @created at 11:52 2024/12/15

class WithdrawalDetailsPage extends StatelessWidget {
  const WithdrawalDetailsPage({super.key});

  @override
  Widget build(BuildContext context) {
    return ProviderScaffold<WithdrawalDetailsViewmodel>(
      model: WithdrawalDetailsViewmodel(ApiLogin.withdrawalList),
      onInit: (data) => data.firstLoad(),
      appBar: (_) => xfgAppbar(title: '提现记录'),
      backgroundColor: XfgColor.white,
      builder: (ctx, detail) => SmartRefresher(
        controller: detail.controller,
        enablePullDown: true,
        enablePullUp: true,
        onRefresh: detail.refresh,
        onLoading: detail.loadMore,
        child: ListView.builder(
          itemCount: detail.list.length,
          itemBuilder: (_, index) {
            final record = detail.list[index];
            return Container(
              margin: EdgeInsets.symmetric(horizontal: XfgSize().size10),
              decoration: BoxDecoration(border: Border(top: BorderSide(color: XfgColor.colorE, width: XfgSize().size0_5))),
              padding: EdgeInsets.fromLTRB(XfgSize().size8, XfgSize().size24, XfgSize().size5, XfgSize().size20),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  XfgText('提现', fontSize: XfgSize().text18, color: XfgColor.text1D, bold: FontWeight.bold),
                  Padding(
                    padding: EdgeInsets.symmetric(vertical: XfgSize().size10),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        XfgText('用户提现，扣除余额', fontSize: XfgSize().text14, color: XfgColor.colorB5),
                        XfgText(_getStatusDesc(record.status), fontSize: XfgSize().text14, color: XfgColor.text1)
                      ],
                    ),
                  ),
                  Row(
                    children: [
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            XfgText('提现订单号: ${record.orderNo}', fontSize: XfgSize().text14, color: XfgColor.colorB5),
                            SizedBox(height: XfgSize().size10),
                            XfgText(record.updatedAt?? '--', fontSize: XfgSize().text14, color: XfgColor.colorB5),
                          ],
                        ),
                      ),
                      XfgText('-${record.amount}', fontSize: XfgSize().text24, color: XfgColor.withdrawalMinus, bold: FontWeight.bold),
                    ],
                  )
                ],
              ),
            );
          },
        ),
      ),
    );
  }

  /// 获取提现状态描述
  String _getStatusDesc(int? status) {
    if (status == 1) {
      return '打款成功';
    } else if (status == 2) {
      return '打款失败';
    }
    return '打款中';
  }
}
